/*
 * @Author: your name
 * @Date: 2022-03-17 21:41:57
 * @LastEditTime: 2022-03-20 14:37:57
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \driving\src\user\user.controller.ts
 */
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req } from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse } from '@nestjs/swagger';
import { User } from './entities/user.entity';
import { AuthGuard } from '@nestjs/passport';
import { selectAllPraticeDto } from 'src/practice/dto/update-practice.dto';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}
  // user.controller.ts
 @ApiOperation({ summary: '注册用户' })
 @ApiResponse({ status: 201, type: [User] })
 @Post('register')
 register(@Body() createUser: CreateUserDto) {
    return this.userService.register(createUser);
  }

  @ApiOperation({ summary: '获取用户信息' })
  @ApiBearerAuth() // swagger文档设置token
  @UseGuards(AuthGuard('jwt'))
  @Get('getInfo')
  getUserInfo(@Req() req) {
      return req.user;
  }

  @ApiOperation({ summary: '获取全部用户信息' })
  @ApiBearerAuth() // swagger文档设置token
  @UseGuards(AuthGuard('jwt'))
  @Post('getAllUser')
  async getAllUser(@Body() post:selectAllPraticeDto) {
      return await this.userService.getAllUser(post)
  }

  @ApiOperation({ summary: '删除指定用户' })
  @ApiBearerAuth() // swagger文档设置token
  @UseGuards(AuthGuard('jwt'))
  @ApiParam({name:'id',description:'用户ID'})
  @Get('deleteUser:id')
  async deleteUser(@Param('id') id) {
      return await this.userService.deleteUser(id)
  }

  @ApiOperation({ summary: '修改用户个人信息' })
  @ApiBearerAuth() // swagger文档设置token
  @UseGuards(AuthGuard('jwt'))
  @Post('updateUser')
  async updateUser(@Body() post:CreateUserDto,@Req() req) {
    let newPost = {
      ...post,
      id:req.user.id
    }
      return await this.userService.updateUser(newPost)
  }

  @ApiOperation({ summary: '查看个人详情信息' })
  @ApiBearerAuth() // swagger文档设置token
  @UseGuards(AuthGuard('jwt'))
  @Get('getUserDeil')
  async getUserDeil(@Req() req) {
      return await this.userService.deleteUser(req.user.id)
  }

  @ApiOperation({ summary: '查看个人详情信息' })
  @ApiBearerAuth() // swagger文档设置token
  @ApiParam({name:'id',description:'用户ID'})
  @UseGuards(AuthGuard('jwt'))
  @Get('getUserDeilById:id')
  async getUserDeilById(@Param('id') id) {
      return await this.userService.getUserDeilById(id)
  }

  @ApiOperation({ summary: '获取全部学员用户信息' })
  @ApiBearerAuth() // swagger文档设置token
  @UseGuards(AuthGuard('jwt'))
  @Get('getAllTrainee')
  async getAllTrainee() {
      return await this.userService.getAllTrainee()
  }
}
